package com.gzw.dms.base;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.gzw.dms.R;
import com.gzw.dms.bean.SpinnerInfo;

import java.util.List;

public class BaseSpinnerAdapter extends BaseAdapter {

    private Context mContext;
    private List<SpinnerInfo> ls;

    public BaseSpinnerAdapter(Context _mContext, List<SpinnerInfo> _ls) {
        this.mContext = _mContext;
        this.ls = _ls;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return ls.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return ls.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if (convertView == null) {
            LayoutInflater _LayoutInflater = LayoutInflater.from(mContext);
            convertView = _LayoutInflater.inflate(R.layout.item_base_spinner, null);
//            convertView = inflate(R.layout.item_base_spinner, null);

        }


        TextView _TextView1 = (TextView) convertView.findViewById(R.id.tv_text);

        _TextView1.setText(ls.get(position).getText());
        _TextView1.setTag(ls.get(position).getId());

        return convertView;
    }

    @Override
        public View getDropDownView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        if (convertView == null) {
            LayoutInflater _LayoutInflater = LayoutInflater.from(mContext);
            convertView = _LayoutInflater.inflate(R.layout.item_base_spinner_child, null);
        }
        TextView _TextView1 = (TextView) convertView.findViewById(R.id.textView1);
        _TextView1.setText(ls.get(position).getText());
        _TextView1.setTag(ls.get(position).getId());
        return convertView;
    }
}
